package com.wwg.spring.bean.factory.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @类描述: TODO
 * @Author wwg
 * @date: 2021/7/15 13:41
 * @Version: 1.0
 **/
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBeanPostProcessor  》》》  postProcessBeforeInitialization  beanName = " + bean);
        if (bean instanceof Runnable){
            new Thread((Runnable) bean).start();
        }
        if (bean instanceof Serializable) System.out.println("bean:"+bean +"can be serializable");

        return bean;

    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBeanPostProcessor  》》》  postProcessAfterInitialization beanName = " + bean);
        return bean;
    }
}
